package part16;

import java.util.Arrays;
import java.util.Collections;

/**
 * @author wcj
 * @Date 2021/5/31 17:50
 * @Version 1.0
 */
public class Part1610 implements Comparable<Part1610> {

    private int i;
    private int j;
    private static int count = 1;

    public Part1610(int i, int j) {
        this.i = i;
        this.j = j;
    }

    @Override
    public String toString() {
        String result = "[i = " + i + ",j = " + j + "]";
        if (count++ % 3 == 0) {
            result += "\n";
        }
        return result;
    }

    @Override
    public int compareTo(Part1610 o) {
        return (i < o.i ? -1 : (i == o.i ? 0 : 1));
    }

    /**
     * Arrays.sort()方法，用于排序数组中的元素，但是这个数组的元素必须是实现了Comparable接口
     * Collections.reverseOrder()方法可以反转数组中元素的顺序
     *
     * @param args
     */
    public static void main(String[] args) {
        Part1610[] arr = {new Part1610(10, 5), new Part1610(20, 9), new Part1610(5, 36)};
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));

        Arrays.sort(arr, Collections.reverseOrder());
        System.out.println(Arrays.toString(arr));
    }
}
